package com.example.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
//设定将在含有这两个注解的类里生效
@ControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler {
   @ResponseBody
   @ExceptionHandler
    public R<String> exceptionHandler(Exception e){
        log.info("出现异常！！！"+e.getMessage());
        return R.error(e.getMessage());
    }
}
